package com.njlime.cms.service.app;

import com.njlime.cms.entities.CommunityCommentUp;
import com.njlime.cms.repository.app.AppCommunityCommentUpDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Created by Dean on 2017/10/10.
 */
@Service
public class AppCommunityCommentUpService {
    @Resource
    AppCommunityCommentUpDao appCommunityCommentUpDao;
    @Resource
    AppCommunityCommentService appCommunityCommentService;

    /**
     * 判断当前community评论是否被点赞
     */
    public Boolean isUped(Integer commentId, Integer userId) {
        int upCount = appCommunityCommentUpDao.userUpCount(commentId, userId);
        if (upCount > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 点赞
     */
    @Transactional(readOnly = false)
    public void save(CommunityCommentUp communityCommentUp) {
        appCommunityCommentUpDao.save(communityCommentUp);
        appCommunityCommentService.fabulousNumUpdate(communityCommentUp.getComment_id(), 1);
    }

    /**
     * 取消点赞
     */
    @Transactional(readOnly = false)
    public void del(Integer commentId, Integer userId) {
        appCommunityCommentUpDao.del(commentId, userId);
        appCommunityCommentService.fabulousNumUpdate(commentId, -1);
    }
}

